package com.yanqu.road.server.cmd.activity.ghost;

import com.yanqu.road.entity.activity.ghost.GhostData;
import com.yanqu.road.pb.activity.GhostActivityProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.cross.battle.ghost.GhostActivity;
import com.yanqu.road.server.manager.cross.battle.ghost.GhostMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;

import java.util.List;
import java.util.Map;

@Cmd(code = CrossProtocol.C2_GHOST_ACTIVITY_UPLOAD_ABILITY, desc = "接收区服能力值通知")
public class CrossGhostUploadAbilityCmd extends CrossCommand {

    private int activityId;
    private List<Long> abilityList;
    private long serverId;

    private List<GhostActivityProto.UserAbilityItem> userAbilityList;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        GhostActivityProto.UploadAbilityReqMsg reqMsg = GhostActivityProto.UploadAbilityReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        abilityList = reqMsg.getAbilityListList();
        serverId = reqMsg.getServerId();
        userAbilityList = reqMsg.getUserAbilityListList();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        GhostActivity activity = GhostMgr.getActivity(activityId);
        if (activity != null) {
            GhostData ghostData = activity.getGhostData();
            Map<Long, List<Long>> abilityMap = ghostData.getAbilityMap();
            if (!abilityMap.containsKey(serverId)) {
                abilityMap.put(serverId, abilityList);
                ghostData.setUpdateOption();
            }
            //玩家门客总赚钱LIST
            activity.addUserAbilityList(serverId, userAbilityList);
        }
    }

    @Override
    public void sendData() {

    }
}
